package com.zero2oneit.mall.service.goods.remote;

import com.zero2oneit.mall.common.annotion.OperateLog;
import com.zero2oneit.mall.common.bean.goods.GoodsCategory;
import com.zero2oneit.mall.common.bean.goods.GoodsProductInfo;
import com.zero2oneit.mall.common.enums.BusinessType;
import com.zero2oneit.mall.common.query.goods.GoodsProductInfoQueryObject;
import com.zero2oneit.mall.common.utils.R;
import com.zero2oneit.mall.common.utils.bootstrap.BoostrapDataGrid;
import com.zero2oneit.mall.feign.goods.CommunityGoodsFeign;
import com.zero2oneit.mall.feign.goods.GoodsCategoryFeign;
import com.zero2oneit.mall.feign.oss.OssFeign;
import com.zero2oneit.mall.system.base.utils.UserContext;
import com.zero2oneit.mall.system.user.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description: 远程调用商品管理（社区团购）服务
 *
 * @author Tg
 * @email zero2oneit@163.com
 * @date 2021/2/5
 */
@RestController
@RequestMapping("/remote/goods")
@CrossOrigin
public class GoodsRemote {

    @Autowired
    private OssFeign ossFeign;

    @Autowired
    private GoodsCategoryFeign categoryFeign;

    /**
     * 获取商品分类(全国)树集合
     * @return
     */
    @PostMapping("/tree")
    public R tree() {
        return R.ok(categoryFeign.tree());
    }

    /**
     * sku 上传图片
     * @param file
     * @return
     */
    @PostMapping("/images")
    public R images(@RequestParam("file") MultipartFile[] file){
        String imgUrl = "";
        if (file != null && file.length >= 1) {
            imgUrl = ossFeign.uploadImage(file, "goods/productPicture");
        }
        Map map = new HashMap<>();
        map.put("imgUrl", imgUrl);
        return R.ok(map);
    }


}
